/*
  * The calculation of the tones is made following the mathematical
 * operation:
 *
 *       timeHigh = 1/(2 * toneFrequency) = period / 2
 *
 * where the different tones are described as in the table:
 *
 * note         frequency       period  PW (timeHigh)   
 * c            261 Hz          3830    1915    
 * d            294 Hz          3400    1700    
 * e            329 Hz          3038    1519    
 * f            349 Hz          2864    1432    
 * g            392 Hz          2550    1275    
 * a            440 Hz          2272    1136    
 * b            493 Hz          2028    1014    
 * C            523 Hz          1912    956
 *
 */



void playTone(int hz, int cycles)
{
  int pulseWidth = 1000000 / (2 * hz);
  for (int toneCycles = 0; toneCycles < 60; toneCycles++)
  {
    analogWrite(speakerOut,255);
    delayMicroseconds(pulseWidth);
    analogWrite(speakerOut, 0);
    delayMicroseconds(pulseWidth);
  }
}


